package top.summerthread.thinking.in.spring.ioc.overview.dependency.injection;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.Environment;
import top.summerthread.thinking.in.spring.ioc.overview.domain.User;
import top.summerthread.thinking.in.spring.ioc.overview.repository.UserRepository;

public class DependencyInjectionDemo {

    public static void main(String[] args) {
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("META-INF/dependency-injection-context.xml");
        UserRepository userRepository = beanFactory.getBean("userRepository",UserRepository.class);
//        System.out.println(userRepository.getUsers());

        System.out.println(userRepository.getBeanFactory() == beanFactory);

        ObjectFactory objectFactory = userRepository.getObjectFactory();
        System.out.println(objectFactory.getObject());

        Environment environment = beanFactory.getBean(Environment.class);
        System.out.println(environment);
    }

    private static void whoIsIocContainer(UserRepository userRepository,BeanFactory beanFactory) {

    }
}
